﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_PersonTrainForm
 * 类型：       控制层
 * 功能说明：   培训申请页面
 * 作者：       徐傲明
 * 创建日期：   2008/3/13
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using log4net;
using Shpm.App.Commons.Utils;
using Shpm.System.Validator;
using Shpm.System.Web.Control;


public partial class App_Input_PersonTrainForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Context.Items["PERSON_ID"] != null)
            {
                ViewState["PERSON_ID"] = Context.Items["PERSON_ID"];

            }
            else
            {
                ViewState["PERSON_ID"] = null;
            }
            if (Context.Items["EMPLOYEE_ID"] != null)
            {
                ViewState["EMPLOYEE_ID"] = Context.Items["EMPLOYEE_ID"];
            }
            else
            {
                ViewState["EMPLOYEE_ID"] = null;
            }
            // 接收传递参数为分页编号
            if (Context.Items.Contains("ParamPageIndex"))
            {
                ViewState["ParamPageIndex"] = Convert.ToString(Context.Items["ParamPageIndex"]);
                GridView.PageIndex = Convert.ToInt32(ViewState["ParamPageIndex"]);
            }
            // 接收传递参数为父页编号
            if (Context.Items.Contains("URL"))
            {
                ViewState["URL"] = Convert.ToString(Context.Items["URL"]);
            }
            if (Context.Items.Contains("CMB_GROUP_ID"))
            {
                this.ViewState["CMB_GROUP_ID"] = Context.Items["CMB_GROUP_ID"];
            }
            if (Context.Items.Contains("CMB_JOB_ID"))
            {
                this.ViewState["CMB_JOB_ID"] = Context.Items["CMB_JOB_ID"];
            }
            if (Context.Items.Contains("CMB_STATUS_ID"))
            {
                this.ViewState["CMB_STATUS_ID"] = Context.Items["CMB_STATUS_ID"];
            }
            if (Context.Items.Contains("EMPLOYEE_STATUS"))
            {
                this.ViewState["EMPLOYEE_STATUS"] = Context.Items["EMPLOYEE_STATUS"];
            }
            if (Context.Items.Contains("CMB_EMPLOYEE_ID"))
            {
                this.ViewState["CMB_EMPLOYEE_ID"] = Context.Items["CMB_EMPLOYEE_ID"];
            }
            if (Context.Items.Contains("CMB_EMPLOYEE_NAME"))
            {
                this.ViewState["CMB_EMPLOYEE_NAME"] = Context.Items["CMB_EMPLOYEE_NAME"];
            }

        }

    }

    void Page_PreRender(object sender, EventArgs e)
    {
        //加载数据
        PersonTrainBean bean = new PersonTrainBean();
        PersonTrainDao dao = new PersonTrainDao();
        bean.EmployeeId = Convert.ToString(ViewState["EMPLOYEE_ID"]);
        IList list = dao.GetListPersonTrain(bean);
        GridView.DataSource = list;
        GridView.DataBind();
    }


    #region 设置标签
    protected void lnkTab_Command(object sender, CommandEventArgs e)
    {
        string directUrl = "~/App/Input/SaleProcesseMembershipForm.aspx";
        switch (e.CommandName)
        {
            case "btn0":
                // 基本信息
                // this.LinkButton1.CssClass = "selectli";
                // this.LinkButton2.CssClass = "";
                directUrl = "~/App/Input/PersonInfoForm.aspx";
                break;
            case "btn1":
                // 学历

                directUrl = "~/App/Input/PersonInfoEdu.aspx";
                break;
            case "btn3":
                // 工作经历
                directUrl = "~/App/Input/PersonInfoWork.aspx";
                break;
            case "btn2":
                // 家庭情况
                directUrl = "~/App/Input/PersonInfoFamily.aspx";
                break;
            case "btn4":
                // 福利
                directUrl = "~/App/Input/PersonInfoWelfare.aspx";
                break;
            case "btn5":
                //薪酬
                directUrl = "~/App/Input/PersonInfoSalaryForm.aspx";
                break;
            case "btn6":
                //奖惩
                directUrl = "~/App/Input/PersonBonusPenaltyForm.aspx";
                break;
            case "btn7":
                //报道
                directUrl = "~/App/Input/PersonPrepareForm.aspx";
                break;
            case "btn8":
                //培训
                directUrl = "~/App/Input/PersonTrainForm.aspx";
                break;
            default:
                break;
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["PERSON_ID"])))
        {
            Context.Items["PERSON_ID"] = this.ViewState["PERSON_ID"];
            Context.Items["EMPLOYEE_ID"] = this.ViewState["EMPLOYEE_ID"];
            Context.Items["CMB_JOB_ID"] = ViewState["CMB_JOB_ID"];
            Context.Items["CMB_GROUP_ID"] = ViewState["CMB_GROUP_ID"];
            Context.Items["CMB_STATUS_ID"] = ViewState["CMB_STATUS_ID"];
            Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
            Context.Items["URL"] = ViewState["URL"];
            Context.Items["EMPLOYEE_STATUS"] = ViewState["EMPLOYEE_STATUS"];
            ControllerUtils.Transfer(this.Context, directUrl, false);
        }
        else
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                          HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0035").ToString();
        }
    }
    #endregion

    protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        //审批状态加载
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //申请状态
            if ("0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).EducateFlg)) &&
                "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).LeadFlg)) &&
                "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CommitFlg)) &&
                        "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).AuditingFlg)) &&
                        "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CancelFlg)))
            {

                e.Row.Cells[4].Text = "未提交";
                //if (((PersonTrainBean)e.Row.DataItem).EmployeeId == userId)
                //{
                //    ((ImageButton)e.Row.FindControl("ImageButton1")).Enabled = true;
                //}
                //else
                //{
                //    ((ImageButton)e.Row.FindControl("ImageButton1")).Enabled = false;
                //}
                //((ImageButton)e.Row.FindControl("ImageButton2")).Enabled = true;
            }
            //审批状态
            else if ("1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).EducateFlg)) &&
                        "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).LeadFlg)) &&
                        "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CommitFlg)) &&
                        "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).AuditingFlg)) &&
                        "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CancelFlg)))
            {
                e.Row.Cells[4].Text = "提交中";
                //((ImageButton)e.Row.FindControl("ImageButton1")).Enabled = false;
                //((ImageButton)e.Row.FindControl("ImageButton2")).Enabled = true;
            }
            //审批状态
            else if ("1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).EducateFlg)) &&
                   "1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).LeadFlg)) &&
                   "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CommitFlg)) &&
                   "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).AuditingFlg)) &&
                   "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CancelFlg)))
            {
                e.Row.Cells[4].Text = "提交中";
                //((ImageButton)e.Row.FindControl("ImageButton1")).Enabled = false;
                //((ImageButton)e.Row.FindControl("ImageButton2")).Enabled = true;
            }
            //审批状态
            else if ("1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).EducateFlg)) &&
                   "1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).LeadFlg)) &&
                   "1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CommitFlg)) &&
                   "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).AuditingFlg)) &&
                   "0".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CancelFlg)))
            {
                e.Row.Cells[4].Text = "审批中";
                //((ImageButton)e.Row.FindControl("ImageButton1")).Enabled = false;
                //((ImageButton)e.Row.FindControl("ImageButton2")).Enabled = true;
            }
            //通过
            else if ("1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).AuditingFlg)))
            {
                e.Row.Cells[4].Text = "已审批";
                //((ImageButton)e.Row.FindControl("ImageButton1")).Enabled = false;
                //((ImageButton)e.Row.FindControl("ImageButton2")).Enabled = false;
            }
            //撤消
            else if ("1".Equals(Convert.ToString(((PersonTrainBean)e.Row.DataItem).CancelFlg)))
            {
                e.Row.Cells[4].Text = "已撤消";
                //((ImageButton)e.Row.FindControl("ImageButton1")).Enabled = false;
                //((ImageButton)e.Row.FindControl("ImageButton2")).Enabled = false;
            }
        }
    }


    protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        //获取主键
        string rowId = null;
        int index = Convert.ToInt32(e.NewEditIndex);
        // Get the Key value from the GridView control.
        DataKey key = GridView.DataKeys[index];
        rowId = Convert.ToString(key.Value);
        string url = "~/App/Input/PersonTrainUpdForm.aspx";
        string mainUrl = "~/App/Input/PersonTrainForm.aspx";

        Context.Items["PERSON_ID"] = this.ViewState["PERSON_ID"];
        Context.Items["CMB_JOB_ID"] = ViewState["CMB_JOB_ID"];
        Context.Items["CMB_GROUP_ID"] = ViewState["CMB_GROUP_ID"];
        Context.Items["CMB_STATUS_ID"] = ViewState["CMB_STATUS_ID"];
        Context.Items["URL"] = ViewState["URL"];
        Context.Items["EMPLOYEE_STATUS"] = ViewState["EMPLOYEE_STATUS"];
        Context.Items["ROW_ID"] = rowId;
        Context.Items["ParamPageIndex"] = GridView.PageIndex;
        Context.Items["EMPLOYEE_ID"] = Convert.ToString(ViewState["EMPLOYEE_ID"]);
        Context.Items["MAIN_URL"] = mainUrl;
        //if (checkAuthority(rowId))
        //{
        ControllerUtils.Transfer(Context, url, true);
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        // 传递分页编号
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
        Context.Items["CMB_GROUP_ID"] = Convert.ToString(this.ViewState["CMB_GROUP_ID"]);
        Context.Items["CMB_JOB_ID"] = Convert.ToString(this.ViewState["CMB_JOB_ID"]);
        //string url = Convert.ToString(ViewState["URL"]);
        string url = "~/App/Input/PersonEmployeeSrhForm.aspx";
        ControllerUtils.Transfer(Context, url, true);
    }
    protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //翻页
        GridView.PageIndex = e.NewPageIndex;
    }

}
